package cn.mall.framework.biz;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import cn.mall.common.relation.RelationKit;

@Slf4j
public class SendCallerMessageService {
	
	@Setter
	private JmsTemplate jmsTemplate;

	public void send(final String relationId, final String message,final String srcUUID) {
		try{
    		jmsTemplate.send(new MessageCreator() {
    			@Override
    			public Message createMessage(Session session) throws JMSException {
    				Message msg = session.createTextMessage(message);
    				msg.setJMSCorrelationID(relationId);
    				msg.setStringProperty("uuid", srcUUID);
    				RelationKit.putRelationInto(msg);
    				return msg;
    			}
    		});
    	}catch(Exception e){
    	    log.error("", e);
        }
	}
}
